UNPKG

@medusajs/medusa

Version:

Building blocks for digital commerce

75 lines 2.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DELETE = exports.POST = void 0; const core_flows_1 = require("@medusajs/core-flows"); const utils_1 = require("@medusajs/framework/utils"); const query_config_1 = require("../../../../../returns/query-config"); const POST = async (req, res) => { const { id, action_id } = req.params; const remoteQuery = req.scope.resolve(utils_1.ContainerRegistrationKeys.REMOTE_QUERY); const [exchange] = await remoteQuery((0, utils_1.remoteQueryObjectFromString)({ entryPoint: "order_exchange", variables: { id, }, fields: ["id", "return_id"], }), { throwIfKeyNotFound: true, }); const { result } = await (0, core_flows_1.updateReturnShippingMethodWorkflow)(req.scope).run({ input: { data: { ...req.validatedBody }, return_id: exchange.return_id, action_id, }, }); const queryObject = (0, utils_1.remoteQueryObjectFromString)({ entryPoint: "order_exchange", variables: { id, filters: { ...req.filterableFields, }, }, fields: req.queryConfig.fields, }); const [orderExchange] = await remoteQuery(queryObject); res.json({ order_preview: result, exchange: orderExchange, }); }; exports.POST = POST; const DELETE = async (req, res) => { const remoteQuery = req.scope.resolve(utils_1.ContainerRegistrationKeys.REMOTE_QUERY); const { id, action_id } = req.params; const [exchange] = await remoteQuery((0, utils_1.remoteQueryObjectFromString)({ entryPoint: "order_exchange", variables: { id, }, fields: ["id", "return_id"], }), { throwIfKeyNotFound: true, }); const { result: orderPreview } = await (0, core_flows_1.removeReturnShippingMethodWorkflow)(req.scope).run({ input: { return_id: exchange.return_id, action_id, }, }); const queryObject = (0, utils_1.remoteQueryObjectFromString)({ entryPoint: "return", variables: { id: exchange.return_id, }, fields: query_config_1.defaultAdminDetailsReturnFields, }); const [orderReturn] = await remoteQuery(queryObject); res.json({ order_preview: orderPreview, return: orderReturn, }); }; exports.DELETE = DELETE; //# sourceMappingURL=route.js.map